<?php
/**
 * 
 * @author Iain Edminster
 */
class Bliss_DataReport_Form_Filter extends Zend_Form_SubForm
{
	/**
	 * Class constructor
	 *
	 * @param Bliss_DataReport $report
	 */
	public function  __construct(Bliss_DataReport $report)
	{
		parent::__construct();

		$report->getResults();
		$this->setAttrib('class', 'report-filter');
		foreach($report->getFilters() as $name => $filter) {
			$element	= isset($filter->element) ? $filter->element : 'Text';
			$class		= "Zend_Form_Element_{$element}";
			$params		= isset($filter->params) ? $filter->params->toArray() : array();
			$params		= array_merge(array(
				'label'	=> $filter->getLabel(),
				'value'	=> $filter->getRealValue()
			), $params);

			if(!isset($filter->visible) || $filter->visible === true) {
				$this->addElement(new $class($name, $params));
			}
		}
		
		$this->addElement(new Zend_Form_Element_Submit('submit_filter', 'Update Report'));
	}
}
?>
